using CSharpPro._10_27_01;

namespace CSharpPro;

public class UserServiceImpl : UserService
{
  
    private readonly List<Student> s = new List<Student>();
    private int Id = 1;
    
    public int Add(Student student)
    {
        if (student == null)
            throw new ArgumentNullException(nameof(student));
        
        student.Id = Id++;
      s.Add(student);
        return 1; 
    }

    
    public int Delete(int id)
    {
        var student =s.FirstOrDefault(s => s.Id == id);
        if (student == null) return 0;
        
        s.Remove(student);
        return 1;
    }

    
    public int Update(Student student)
    {
        if (student == null || student.Id <= 0)
            return 0;

        var existing = s.FirstOrDefault(s => s.Id == student.Id);
        if (existing == null) return 0;
        
        existing.Name = student.Name;
        existing.Age = student.Age;
        return 1;
    }

    
    public List<Student> Query()
    {
        
        return s.ToList();
    }
}